package com.kehongborui.portal.web;

import com.kehongborui.portal.model.DeptModel;
import com.kehongborui.portal.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * @author zhang peng yang ming
 * @CopyRight (C) http://www.csdn.com
 * @brief
 * @email 122162005@qq.com
 * @date 2018-09-26
 */
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @PostMapping
    public Callable<DeptModel> create(@RequestBody DeptModel model) {

        return new Callable<DeptModel>() {
            @Override
            public DeptModel call() throws Exception {
                return model;
            }
        };
//        return model; // for test
//        return deptService.save(model);
    }

    /**
     * 更改部门（组织机构信息）
     * @param model
     */
    @PutMapping
    public void update(@RequestBody DeptModel model) {
        deptService.update(model);
    }

    /**
     * 根据id查询部门（组织机构信息）信息
     * @param id
     */
    @GetMapping("/{id}/{dd}")
    public DeptModel findById(@PathVariable("id") Integer id) {
        return deptService.findById(id);
    }

    /**
     * 根据id删除部门
     * @param id
     */
    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable("id") Integer id) {
        deptService.deleteById(id);
    }

    @GetMapping
    public List<DeptModel> findAll() {
        return deptService.findAll();
    }
}
